<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j" xmlns:p="http://primefaces.org/ui"
	xmlns:t="http://myfaces.apache.org/tomahawk" template="/pages/template/main-layout-oa.xhtml">
	<ui:define name="head">
		<script type="text/javascript">  
		function handleSubmitEvent(xhr, status, args) {  
			if(args.validationFailed || args.therapyError) {  
				//jQuery('#docScheduleDialog').effect("shake", { times:3 }, 100);  
			} else {  
				docScheduleDlg.hide();
			 }  
		}
		</script>
	</ui:define>
	<ui:define name="content">
		<h:panelGrid columns="2" width="100%" columnClasses="width80,width20" cellpadding="5">
			<p:schedule id="doctorSchedule" value="#{doctorScheduleBean.lazyEventModel}" locale="hr"
				timeZone="EST"
				widgetVar="myschedule" resizable="false" draggable="false">
				<p:ajax event="dateSelect" listener="#{doctorScheduleBean.onDateSelect}"
					update=":dialogform:userEventDetails" oncomplete="docScheduleDlg.show()" />

				<p:ajax event="eventSelect" listener="#{doctorScheduleBean.onEventSelect}"
					update=":dialogform:userEventDetails" oncomplete="docScheduleDlg.show()" />
			</p:schedule>

			<p:dataTable value="#{doctorScheduleBean.todayModel}" var="cm" id="todaylist"
				selection="#{doctorScheduleBean.selectedSchedules}">
				<p:column selectionMode="multiple" style="width:18px" />
				<p:column headerText="#{doctorScheduleBean.header}">
					<h:outputText value="#{cm.timeFrom}">
						<f:convertDateTime pattern="HH:mm" />
					</h:outputText>
					<h:outputText value=" - " />
					<h:outputText value="#{cm.timeTo}">
						<f:convertDateTime pattern="HH:mm" />
					</h:outputText>
					<br />
					<h:outputText value="#{cm.domainPatient.patient.surname} #{cm.domainPatient.patient.name}" />
				</p:column>
				<p:column>
					<p:commandButton ajax="false" icon="ui-icon-search" action="#{doctorScheduleBean.linkAction}"
						title="#{msgs.patient_therapy_go}" />
				</p:column>

				<f:facet name="footer">
					<p:commandButton value="#{msgs.patient_reservation_status_finish}" icon="ui-icon-check"
						actionListener="#{doctorScheduleBean.finishTodayAllAction}"
						update=":messages, todaylist, :mainform:doctorSchedule" style="float:left" />
				</f:facet>
			</p:dataTable>
		</h:panelGrid>
	</ui:define>
	<ui:define name="dialog">
		<p:dialog widgetVar="docScheduleDlg" header="#{msgs.patient_reservations}" showEffect="clip"
			hideEffect="clip" closable="true" modal="true" width="800" height="600" id="docScheduleDialog">
			<h:panelGrid id="userEventDetails" width="100%">
				<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
					<h:outputLabel value="#{msgs.patient_therapy_type} *" />
					<p:selectOneMenu value="#{doctorScheduleBean.calendarType}"
						disabled="#{doctorScheduleBean.sEvent.id != null}" required="true"
						label="#{msgs.patient_therapy_type}">
						<f:selectItem itemLabel="" itemValue="" />
						<f:selectItems value="#{sessionEnum['CalendarType']}" var="en" itemLabel="#{en.name}"
							itemValue="#{en.value}" />

						<p:ajax update="pnlPatient, pnlEvent" />
					</p:selectOneMenu>
				</h:panelGrid>

				<p:panel visible="#{doctorScheduleBean.calendarType == 1}" id="pnlPatient">
					<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
						<h:outputLabel value="#{msgs.default_name_surname} *" />
						<h:panelGroup>
							<p:autoComplete completeMethod="#{doctorScheduleBean.completeQueryName}" id="patientname"
								size="40" value="#{doctorScheduleBean.qyPatientName}" forceSelection="true"
								minQueryLength="3">
								<p:ajax event="itemSelect" listener="#{doctorScheduleBean.selectPatientName}" />
							</p:autoComplete>
							<p:commandButton value="#{msgs.patient_therapy_add_into}" onsuccess="therapyDlg.show();"
								immediate="true" icon="ui-icon-plus" autoSubmit="false"
								actionListener="#{doctorScheduleBean.openTherapyListAction}"
								update=":dialogform:therapyList" />
						</h:panelGroup>
						<h:outputLabel value="#{msgs.default_priority}" />
						<p:selectBooleanCheckbox value="#{doctorScheduleBean.doctorSchedule.priority}" />

						<h:outputLabel value="#{msgs.default_status}" />
						<p:selectOneMenu value="#{doctorScheduleBean.doctorSchedule.status}">
							<f:selectItems value="#{sessionEnum['ReservationStatus']}" var="en" itemLabel="#{en.name}"
								itemValue="#{en.value}" />
						</p:selectOneMenu>
					</h:panelGrid>
					<p:panel visible="#{doctorScheduleBean.therapyObj != null}"
						header="#{msgs.patient_therapy_title}" id="pnlTherapy">
						<p:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
							<h:outputLabel value="#{msgs.patient_therapy_startDate}" />
							<h:outputText value="#{doctorScheduleBean.therapyObj[0]}" converter="dateConverter" />

							<h:outputLabel value="#{msgs.therapy_category}" />
							<h:outputText value="#{doctorScheduleBean.therapyObj[1]}" />

							<h:outputLabel value="#{msgs.default_status}" />
							<h:outputText value="#{doctorScheduleBean.therapyObj[2]}" converter="enumConverter"
								enumName="TherapyStatus" />
						</p:panelGrid>
						<f:facet name="footer">
							<p:commandButton value="#{msgs.button_remove}" icon="ui-icon-close"
								actionListener="#{doctorScheduleBean.deleteTherapyAction}" update="pnlTherapy" />
						</f:facet>
					</p:panel>
					
					<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
						<h:outputLabel  value="#{msgs.default_remark}" />
						<p:inputTextarea value="#{doctorScheduleBean.doctorSchedule.content}"
							style="width:100%" rows="5" autoResize="false" />

						<h:outputLabel value="#{msgs.default_from}" />
						<p:calendar value="#{doctorScheduleBean.doctorSchedule.timeFrom}" timeZone="Europe/Zagreb"
							style="validator:checkNotNull(#{msgs.default_from})" pattern="dd/MM/yyyy HH:mm"
							showOn="button" />

						<h:outputLabel value="#{msgs.default_to}" />
						<p:calendar value="#{doctorScheduleBean.doctorSchedule.timeTo}" timeZone="Europe/Zagreb"
							showOn="button" pattern="dd/MM/yyyy HH:mm" />
					</h:panelGrid>
				</p:panel>

				<p:panel visible="#{doctorScheduleBean.calendarType == 2}" id="pnlEvent">
					<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
						<h:outputLabel  value="#{msgs.default_remark}" />
						<p:inputTextarea value="#{doctorScheduleBean.uEvent.title}"
							style="width:100%" rows="5" autoResize="false" />

						<h:outputLabel value="#{msgs.default_from}" />
						<p:calendar value="#{doctorScheduleBean.uEvent.timeFrom}" timeZone="Europe/Zagreb"
							 pattern="dd/MM/yyyy HH:mm"
							showOn="button" />

						<h:outputLabel value="#{msgs.default_to}" />
						<p:calendar value="#{doctorScheduleBean.uEvent.timeTo}" timeZone="Europe/Zagreb"
							 showOn="button" pattern="dd/MM/yyyy HH:mm" />
					</h:panelGrid>
				</p:panel>

				<f:facet name="footer">
					<h:panelGrid columns="2" width="100%" columnClasses="left,right">
						<p:commandButton value="#{msgs.button_delete}"
							actionListener="#{doctorScheduleBean.deleteEvent}" icon="ui-icon-trash"
							oncomplete="myschedule.update();docScheduleDlg.hide();"
							update=":messages,:mainform:todaylist" style="float:left" />

						<h:panelGroup style="float:right">
							<p:commandButton value="#{msgs.button_submit}"
								actionListener="#{doctorScheduleBean.submitEventAction}" icon="ui-icon-disk"
								oncomplete="handleSubmitEvent(xhr, status, args);myschedule.update();"
								update=":messages,:mainform:todaylist" />
							<h:outputText value="&#160;&#160;" escape="false" />
							<p:commandButton value="#{msgs.patient_therapy_go}"
								rendered="#{doctorScheduleBean.doctorSchedule.id != null}"
								action="#{doctorScheduleBean.goTherapyAction}" ajax="false"
								icon="ui-icon-arrowreturnthick-1-e" />
						</h:panelGroup>
					</h:panelGrid>
				</f:facet>
			</h:panelGrid>
		</p:dialog>

		<p:dialog widgetVar="therapyDlg" header="#{msgs.patient_therapy_title}" showEffect="clip"
			hideEffect="clip" closable="true" modal="true" width="800" height="400">
			<p:dataTable id="therapyList" value="#{doctorScheduleBean.therapyModel}" var="te">
				<p:column headerText="#{msgs.patient_therapy_startDate}">
					<h:outputText value="#{te[0]}" converter="dateConverter" />
				</p:column>
				<p:column headerText="#{msgs.therapy_category}">
					<h:outputText value="#{te[1]}" />
				</p:column>
				<p:column headerText="#{msgs.default_status}">
					<h:outputText value="#{te[3]}" converter="enumConverter" enumName="TherapyStatus" />
				</p:column>
				<p:column headerText="#{msgs.patient_therapy_choose}">
					<p:commandLink actionListener="#{doctorScheduleBean.chooseTherapyAction}"
						styleClass="ui-icon ui-icon-flag" title="#{msgs.patient_therapy_choose_lowcase}"
						update=":dialogform:pnlTherapy" onsuccess="therapyDlg.hide();">
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</p:dialog>
	</ui:define>
</ui:composition>
